package com.ljx.demo.service.security;

import com.ljx.demo.security.custom.CustomDynamicSecurityService;
import org.springframework.context.annotation.Bean;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-06-18  13:39
 */
@Component
public class CustomSecurityConfig {

    @Bean
    public CustomDynamicSecurityService dynamicSecurityService() {
        return new CustomDynamicSecurityService() {
            @Override
            public Map<String, ConfigAttribute> loadDataSource() {
                Map<String, ConfigAttribute> map = new ConcurrentHashMap<>();
                // 查询所有权限列表
                // 这里模拟数据
                map.put("/auth/t1", new org.springframework.security.access.SecurityConfig("user:t1"));
                map.put("/auth/t2", new org.springframework.security.access.SecurityConfig("user:t2"));
                map.put("/auth/t3", new org.springframework.security.access.SecurityConfig("user:t3"));

                return map;
            }
        };
    }
}
